package com.wangc.servlet.shouzhi;

import java.io.IOException;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class ServShouzhi
 */
public class ShouzhiServ extends HttpServlet {
	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		if("new".equals(request.getParameter("para"))){
			String type = request.getParameter("type");
			String amount = request.getParameter("amount");
			String detail = request.getParameter("detail");
			boolean flag = ShouzhiDB.insert(type, amount, detail, request);
			if(flag){
				request.getSession().setAttribute("msg", "OK!");
			}else{
				request.getSession().setAttribute("msg", "no OK!");
			}
			response.sendRedirect("../msg.jsp");
			
		}else if("sel".equals(request.getParameter("para"))){
			List<HashMap> shouzhiList = ShouzhiDB.sel();
			List<HashMap> monthList = ShouzhiDB.selMonth();
			request.getSession().setAttribute("list", shouzhiList);
			request.getSession().setAttribute("monthList", monthList);
			request.getRequestDispatcher("shouzhi_list.jsp").forward(request, response);
		}else if("sea".equals(request.getParameter("para"))){
			List <HashMap> list = ShouzhiDB.sea(request);
			request.getSession().setAttribute("list", list);
			request.getRequestDispatcher("shouzhi_list.jsp").forward(request, response);
		}
	}

}
